/*
 * This class should be the root of your parse tree.
 * 
 * Update the class with the variables and constructors
 * you see required.
 * 
 * Update the toString method to prString the tree.
 * 
 * Update the check method such that it checks the
 * tree for semantic errors.
 */

public class ClassDecl {
	String cl;
	String id ;
	String lb;
	MethodDecls m;
	String rb;
	int lineNum;
	int charPos;
	public ClassDecl(String cl, String id, String lb, MethodDecls m, String rb, int line, int charP) {
		this.cl = cl;
		this.id = id;
		this.lb = lb;
		this.m = m;
		this.rb = rb;
		this.lineNum = line;
		this.charPos = charP;
	}
	
	public String toString() {
		String ret = "ClassDecl\n";
		String s = "";
//		String s = cl + id + lb;

		if (m != null) {
			s +=  m.toString();
		}

//		s += rb;

		for(String st: s.split("\n")){
			if(st!= "")
				ret += "| " + st + "\n";
		}

		return ret;
	}
	
	public void check() throws SemanticException {
		SymbolTable table = SymbolTable.getInstance();
		table.openScope();
		table.add(new Entry(id));
		m.check();
		// //System.out.println("if " + table.getNumOfIfs() + " return " + table.getNumOfReturns() + " " + table.getInIf() + " " + table.getUnCondIf());
		table.closeScope();
		// table.print();
	}
}
